﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ignitron.EEngine.Maths;

namespace Ignitron.EEngine.Model
{
    /// <summary>
    /// Single mesh class
    /// </summary>
    public class EMesh
    {
        protected EVector3[] mVertices;
        protected EVector3[] mNormals;
        protected EVector2[] mTexCoords;
        protected uint[] mIndices;

        /// <summary>
        /// Protect from creating outside assembly
        /// </summary>
        internal EMesh()
        {
        }

        public EVector3[] Vertices
        {
            get { return mVertices; }
        }

        public EVector3[] Normals
        {
            get { return mNormals; }
        }

        public EVector2[] TexCoords
        {
            get { return mTexCoords; }
        }

        public uint[] Indices
        {
            get { return mIndices; }
        }

        /// <summary>
        /// Sets the meshes data
        /// </summary>
        public void SetData(EVector3[] vertices, EVector3[] normals, EVector2[] texcoords, uint[] indices)
        {
            // set variables
            mVertices = vertices;
            mNormals = normals;
            mTexCoords = texcoords;
            mIndices = indices;

            // update the native platform resources
            Update();
        }

        /// <summary>
        /// Sets the normal vectors
        /// </summary>
        /// <param name="normals"></param>
        internal void SetNormals(EVector3[] normals)
        {
            mNormals = normals;

            // update the native platform resources
            Update();
        }

        /// <summary>
        /// Sets the texture coordinates
        /// </summary>
        /// <param name="texcoords"></param>
        internal void SetTexCoords(EVector2[] texcoords)
        {
            mTexCoords = texcoords;

            Update();
        }

        /// <summary>
        /// Updates the native platform resources
        /// </summary>
        protected virtual void Update()
        {
        }
    }
}
